#include "stm32f10x.h"
#include "stm32f10x_flash.h"
#include "stmflash.h"

void Flash_Write(uint32_t address, uint32_t data) {
    FLASH_Unlock();  // 解锁Flash

    FLASH_ClearFlag(FLASH_FLAG_EOP | FLASH_FLAG_PGERR | FLASH_FLAG_WRPRTERR);  // 清除所有标志
	
	   // 擦除目标地址页
    FLASH_ErasePage(address);
	
    if (FLASH_ProgramWord(address, data) == FLASH_COMPLETE) {
        //如果写入成功，可在此处加入成功后的处理代码
    }

    FLASH_Lock();  // 上锁Flash
}

uint32_t Flash_Read(uint32_t address) {
    return *(__IO uint32_t*)address;
}
